/******************************************************************************/
/*                                                                            */
/*  Copyright (c) 2009: ngi-central.org                                       */
/*  All rights reserved.                                                      */
/*                                                                            */
/******************************************************************************/


#include <boost/test/unit_test.hpp>

#include "..\..\include\sgl\central_moments.h"

BOOST_AUTO_TEST_SUITE( central_moments )


BOOST_AUTO_TEST_CASE( central_moments__default_constructor )
{
	sgl::central_moments<> a;

	BOOST_CHECK( a.mu00() == 0 );
	BOOST_CHECK( a.mu20() == 0 );
	BOOST_CHECK( a.mu11() == 0 );
	BOOST_CHECK( a.mu02() == 0 );
	BOOST_CHECK( a.mu30() == 0 );
	BOOST_CHECK( a.mu21() == 0 );
	BOOST_CHECK( a.mu12() == 0 );
	BOOST_CHECK( a.mu03() == 0 );

	sgl::central_moments<> b(1, 1, 2, 3, 4, 5, 6, 7);

	BOOST_CHECK( b.mu00() == 1 );
	BOOST_CHECK( b.mu20() == 1 );
	BOOST_CHECK( b.mu11() == 2 );
	BOOST_CHECK( b.mu02() == 3 );
	BOOST_CHECK( b.mu30() == 4 );
	BOOST_CHECK( b.mu21() == 5 );
	BOOST_CHECK( b.mu12() == 6 );
	BOOST_CHECK( b.mu03() == 7 );
}

BOOST_AUTO_TEST_CASE( central_moments__copy_constructor )
{
	sgl::central_moments<> a(
		sgl::central_moments<>(1, 1, 2, 3, 4, 5, 6, 7));

	BOOST_CHECK( a.mu00() == 1 );
	BOOST_CHECK( a.mu20() == 1 );
	BOOST_CHECK( a.mu11() == 2 );
	BOOST_CHECK( a.mu02() == 3 );
	BOOST_CHECK( a.mu30() == 4 );
	BOOST_CHECK( a.mu21() == 5 );
	BOOST_CHECK( a.mu12() == 6 );
	BOOST_CHECK( a.mu03() == 7 );
}

BOOST_AUTO_TEST_CASE( normalized_moments__conversion_copy_constructor )
{
	sgl::central_moments<> a(
		sgl::normalized_moments<>(1, 1, 2, 3, 4, 5, 6, 7, 8, 9));

	BOOST_CHECK( a.mu00() == 1 );
	BOOST_CHECK( a.mu20() == 2 );
	BOOST_CHECK( a.mu11() == 2 );
	BOOST_CHECK( a.mu02() == 1 );
	BOOST_CHECK( a.mu30() == -1 );
	BOOST_CHECK( a.mu21() == -3 );
	BOOST_CHECK( a.mu12() == -5 );
	BOOST_CHECK( a.mu03() == -5 );
}

BOOST_AUTO_TEST_CASE( central_moments__copy_assignment )
{
	sgl::central_moments<> a;
	a = sgl::central_moments<>(1, 1, 2, 3, 4, 5, 6, 7);

	BOOST_CHECK( a.mu00() == 1 );
	BOOST_CHECK( a.mu20() == 1 );
	BOOST_CHECK( a.mu11() == 2 );
	BOOST_CHECK( a.mu02() == 3 );
	BOOST_CHECK( a.mu30() == 4 );
	BOOST_CHECK( a.mu21() == 5 );
	BOOST_CHECK( a.mu12() == 6 );
	BOOST_CHECK( a.mu03() == 7 );
}

BOOST_AUTO_TEST_CASE( central_moments__swap )
{
	sgl::central_moments<> a(
		sgl::central_moments<>(1, 1, 2, 3, 4, 5, 6, 7));
	sgl::central_moments<> b;

	a.swap(b);

	BOOST_CHECK( a.mu00() == 0 );
	BOOST_CHECK( a.mu20() == 0 );
	BOOST_CHECK( a.mu11() == 0 );
	BOOST_CHECK( a.mu02() == 0 );
	BOOST_CHECK( a.mu30() == 0 );
	BOOST_CHECK( a.mu21() == 0 );
	BOOST_CHECK( a.mu12() == 0 );
	BOOST_CHECK( a.mu03() == 0 );
	BOOST_CHECK( b.mu00() == 1 );
	BOOST_CHECK( b.mu20() == 1 );
	BOOST_CHECK( b.mu11() == 2 );
	BOOST_CHECK( b.mu02() == 3 );
	BOOST_CHECK( b.mu30() == 4 );
	BOOST_CHECK( b.mu21() == 5 );
	BOOST_CHECK( b.mu12() == 6 );
	BOOST_CHECK( b.mu03() == 7 );

	b.swap(a);

	BOOST_CHECK( a.mu00() == 1 );
	BOOST_CHECK( a.mu20() == 1 );
	BOOST_CHECK( a.mu11() == 2 );
	BOOST_CHECK( a.mu02() == 3 );
	BOOST_CHECK( a.mu30() == 4 );
	BOOST_CHECK( a.mu21() == 5 );
	BOOST_CHECK( a.mu12() == 6 );
	BOOST_CHECK( a.mu03() == 7 );
	BOOST_CHECK( b.mu00() == 0 );
	BOOST_CHECK( b.mu20() == 0 );
	BOOST_CHECK( b.mu11() == 0 );
	BOOST_CHECK( b.mu02() == 0 );
	BOOST_CHECK( b.mu30() == 0 );
	BOOST_CHECK( b.mu21() == 0 );
	BOOST_CHECK( b.mu12() == 0 );
	BOOST_CHECK( b.mu03() == 0 );
}

BOOST_AUTO_TEST_CASE( central_moments__mu00 )
{
	sgl::central_moments<> a;

	BOOST_CHECK( a.mu00() == 0 );

	a.mu00() = 1;

	BOOST_CHECK( a.mu00() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__mu20 )
{
	sgl::central_moments<> a;

	BOOST_CHECK( a.mu20() == 0 );

	a.mu20() = 1;

	BOOST_CHECK( a.mu20() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__mu11 )
{
	sgl::central_moments<> a;

	BOOST_CHECK( a.mu11() == 0 );

	a.mu11() = 1;

	BOOST_CHECK( a.mu11() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__mu02 )
{
	sgl::central_moments<> a;

	BOOST_CHECK( a.mu02() == 0 );

	a.mu02() = 1;

	BOOST_CHECK( a.mu02() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__mu30 )
{
	sgl::central_moments<> a;

	BOOST_CHECK( a.mu30() == 0 );

	a.mu30() = 1;

	BOOST_CHECK( a.mu30() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__mu21 )
{
	sgl::central_moments<> a;

	BOOST_CHECK( a.mu21() == 0 );

	a.mu21() = 1;

	BOOST_CHECK( a.mu21() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__mu12 )
{
	sgl::central_moments<> a;

	BOOST_CHECK( a.mu12() == 0 );

	a.mu12() = 1;

	BOOST_CHECK( a.mu12() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__mu03)
{
	sgl::central_moments<> a;

	BOOST_CHECK( a.mu03() == 0 );

	a.mu03() = 1;

	BOOST_CHECK( a.mu03() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__operator_equality )
{
	sgl::central_moments<> a;
	sgl::central_moments<> b;

	BOOST_CHECK( a == b );

	sgl::central_moments<> c(1, 1, 2, 3, 4, 5, 6, 7);
	sgl::central_moments<> d(1, 1, 2, 3, 4, 5, 6, 7);

	BOOST_CHECK( c == d );
}

BOOST_AUTO_TEST_CASE( central_moments__operator_inequality )
{
	sgl::central_moments<> a;
	sgl::central_moments<> b(1, 1, 2, 3, 4, 5, 6, 7);

	BOOST_CHECK( a != b );
}

BOOST_AUTO_TEST_CASE( central_moments__calculate_eta20 )
{
	sgl::central_moments<> a;

	a.mu20() = 4;
	BOOST_CHECK_THROW( a.calculate_eta20(), sgl::precondition_violated );

	a.mu00() = 2;

	BOOST_CHECK( a.calculate_eta20() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__calculate_eta11 )
{
	sgl::central_moments<> a;

	a.mu11() = 4;
	BOOST_CHECK_THROW( a.calculate_eta11(), sgl::precondition_violated );

	a.mu00() = 2;

	BOOST_CHECK( a.calculate_eta11() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__calculate_eta02 )
{
	sgl::central_moments<> a;

	a.mu02() = 4;
	BOOST_CHECK_THROW( a.calculate_eta02(), sgl::precondition_violated );

	a.mu00() = 2;

	BOOST_CHECK( a.calculate_eta02() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__calculate_eta30 )
{
	sgl::central_moments<> a;

	a.mu30() = 32;
	BOOST_CHECK_THROW( a.calculate_eta30(), sgl::precondition_violated );

	a.mu00() = 4;

	BOOST_CHECK( a.calculate_eta30() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__calculate_eta21 )
{
	sgl::central_moments<> a;

	a.mu21() = 32;
	BOOST_CHECK_THROW( a.calculate_eta21(), sgl::precondition_violated );

	a.mu00() = 4;

	BOOST_CHECK( a.calculate_eta21() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__calculate_eta12 )
{
	sgl::central_moments<> a;

	a.mu12() = 32;
	BOOST_CHECK_THROW( a.calculate_eta12(), sgl::precondition_violated );

	a.mu00() = 4;

	BOOST_CHECK( a.calculate_eta12() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__calculate_eta03)
{
	sgl::central_moments<> a;

	a.mu03() = 32;
	BOOST_CHECK_THROW( a.calculate_eta03(), sgl::precondition_violated );

	a.mu00() = 4;

	BOOST_CHECK( a.calculate_eta03() == 1 );
}

BOOST_AUTO_TEST_CASE( central_moments__calculate_fm1 )
{
	sgl::central_moments<> a;

	BOOST_CHECK_THROW( a.calculate_fm1(), sgl::precondition_violated );

	a = sgl::central_moments<>(1, 1, 2, 3, 4, 5, 6, 7);

	BOOST_CHECK( a.calculate_fm1() == -1 );
}

BOOST_AUTO_TEST_CASE( central_moments__calculate_fm2 )
{
	sgl::central_moments<> a;

	BOOST_CHECK_THROW( a.calculate_fm2(), sgl::precondition_violated );

	a = sgl::central_moments<>(1, 1, 2, 3, 4, 5, 6, 7);

	BOOST_CHECK( a.calculate_fm2() == 0 );
}

BOOST_AUTO_TEST_CASE( central_moments__calculate_fm3 )
{
	sgl::central_moments<> a;

	BOOST_CHECK_THROW( a.calculate_fm3(), sgl::precondition_violated );

	a = sgl::central_moments<>(1, 1, 2, 3, 4, 5, 6, 7);

	BOOST_CHECK( a.calculate_fm3() == 0 );
}

BOOST_AUTO_TEST_CASE( central_moments__calculate_fm4 )
{
	sgl::central_moments<> a;

	BOOST_CHECK_THROW( a.calculate_fm4(), sgl::precondition_violated );

	a = sgl::central_moments<>(1, 1, 2, 3, 4, 5, 6, 7);

	BOOST_CHECK( a.calculate_fm4() == 0 );
}

BOOST_AUTO_TEST_SUITE_END()

